package com.yudaob2b.elong.service;

import com.yudaob2b.business.service.ElongHotelListService;
import com.yudaob2b.common.utils.PageUtil;
import com.yudaob2b.elong.constant.RedisConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 重置redis数据service
 *
 * @author Kidd.Tan
 * @email 298023780@qq.com
 * @date 7/15/18 6:23 PM
 */
@Service("redisInitService")
public class RedisInitService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final int PAGE_SIZE = 10000;

    @Autowired
    private ElongHotelListService elongHotelListService;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 酒店id列表全部缓存到redis
     */
    public void inithotelListId() {
        Map<String, Object> condition = new HashMap<>();
        condition.put("status", "0");
        int page = 1;
        while (true) {
            PageUtil.setPage(page, PAGE_SIZE, condition);
            List<String> list = elongHotelListService.queryHotelIdListPage(condition);
            for (String hotelId : list) {
                redisTemplate.opsForList().leftPush(RedisConstant.REDIS_HOTEL_ID_LIST_KEY, hotelId);
            }

            page++;
        }


    }
}
